﻿using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using GitNet.WindowsApp.ViewModels;

namespace GitNet.WindowsApp.AddViews;

public partial class AddBranchView : UserControl
{
    public AddBranchView()
    {
        InitializeComponent();
        NameBox = this.FindControl<TextBox>("NameBox");
        Down = this.FindControl<NumericUpDown>("Down");
        Down.Minimum = 0;
    }

    private void InitializeComponent()
    {
        AvaloniaXamlLoader.Load(this);
    }

    private void OkClick(object? sender, RoutedEventArgs e)
    {
        if(Parent?.DataContext is not RepositoryViewModel model)return;
        if(string.IsNullOrEmpty(NameBox.Text))return;
        model.CreateBranch(NameBox.Text,(int)Down.Value);
    }
}